﻿using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using System.Linq.Expressions;
using RentAWorker.Business.WebHost.Code;
using System.Security;

namespace RentAWorker.Business.WebHost.DataService
{
    public class SilverlightDataService : DataService<BigDays2009EntitiesSimple>
    {
        public static void InitializeService(IDataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
            // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
        }

        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            if (!RentAWorkerGroupHelper.IsCurrentUserInRole("FrontOffice"))
                throw new SecurityException("Only front-office members may manage these entities! If using Vista, run your client as Admin!");

            base.OnStartProcessingRequest(args);
        }
    }
}
